package com.study.langchain4j.api;

import dev.langchain4j.model.input.PromptTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author xl-9527
 * @since 2025/10/31
 **/
@RestController
@RequestMapping("ai/prompt/prompt-template")
public class PromptTemplateApi {

    /* 定义一个提示词，这个提示词是系统提示词，它主要是定义你的角色信息 */
    private final PromptTemplate systemPromptTemplate;

    public PromptTemplateApi() {
        this.systemPromptTemplate = PromptTemplate.from("You are a {{role}} assistant. you work is {{work}}");
    }

    @GetMapping("scientist")
    public String scientist(@RequestParam("role") String role, @RequestParam("work") String work) {
        return systemPromptTemplate.apply(Map.of("role", role, "work", work)).toSystemMessage().text();
    }
}
